package com.xiaode.controller.app.selfStudyRoom;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.common.anotation.UserType;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import com.xiaode.validator.SensitiveWordValidator;

/**
 * 自习室
 */
@Path("/selfStudyRoom")
@Api("自习室")
@EnableCORS
public class SelfStudyRoomController extends Controller {
	
	 @Inject
	 private SelfStudyService service;
	 
	 
	 /**
	  * 获取监控教室
	  */
	 @ApiOper("获取监控教室")
	 @UserType(conType = {1})
	 public void getMonitorClassroomList() throws Exception{
		 Ret ret = service.getMonitorClassroomList();
		 renderJson(ret);
	 }
	 
	 /**
	  * 获取某个教室摄像头监控流
	  */
	 @ApiOper("获取某个教室摄像头监控流")
	 @UserType(conType = {1})
	 public void getPreviewURLs(@NotBlank @ApiPara(value = "monitorClassroomId", notes = "监控教室id")Integer monitorClassroomId) throws Exception{
		 Ret ret = service.getPreviewURLs(monitorClassroomId);
		 renderJson(ret);
	 }
	 
	 /**
	  * 获取摄像头回放流
	  */
	 @ApiOper("获取摄像头回放流")
	 @UserType(conType = {1})
	 public void getPlaybackURL(
			 @NotEmpty @ApiPara(value = "cameraId", notes = "id")Integer cameraId, 
			 @NotBlank @ApiPara(value = "beginTime", notes = "开始时间")String beginTime, 
			 @NotBlank @ApiPara(value = "endTime", notes = "结束时间")String endTime) throws Exception{
		 Ret ret = service.getPlaybackURL(cameraId, beginTime, endTime);
		 renderJson(ret);
	 }
	 
	 /**
	  * 获取教室内的人数
	  * 此接口是轮询，后期时间充足可优化为，通过聊天服务器主动推送
	  */
	 @ApiOper("获取教室内的人数")
	 @UserType(conType = {1})
	 public void getRoomPeopleNum(@NotEmpty @ApiPara(value = "monitorClassroomId", notes = "id")Integer monitorClassroomId) throws Exception{
		 Ret ret = service.getRoomPeopleNum(monitorClassroomId);
		 renderJson(ret);
	 }
	 
	 /**
	  * 上传/修改 人脸
	  * 需要判断base64是否是 图片的大小范围在10KB到200KB之间，只支持JGP格式图片
	  */
	 @ApiOper("上传/修改 人脸")
	 @Clear(SensitiveWordValidator.class)
	 public void uploadFace(@NotEmpty @ApiPara(value = "faceBase64", notes = "图片的base64（jpg）")String faceBase64) throws Exception{
		 Integer accountId = getAttr("accountId");
		 Integer userType = getAttr("userType");
		 Ret ret = service.uploadFace(accountId, userType, faceBase64);
		 renderJson(ret);
	 }
	 
	 /**
	  * 老师需要审核人脸的数量
	  * 老师管理的学生
	  */
	 @ApiOper("老师需要审核人脸的数量")
	 @UserType(conType = {1})
	 public void needExamineCount() throws Exception{
		 Integer userId = getAttr("userId");
		 Ret ret = service.needExamineCount(userId);
		 renderJson(ret);
	 }
	 
	 /**
	  * 老师审核人脸列表
	  * 老师管理的学生
	  */
	 @ApiOper("老师审核人老师绑定的学生脸列表")
	 @UserType(conType = {1})
	 public void faceList(
			 @NotBlank @JSONArrayString @ApiPara(value = "states", notes = "状态数组[]")String states, 
			 @NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page, 
			 @NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
		 Integer userId = getAttr("userId");
		 Ret ret = service.studentFacePage(userId, states, page, limit);
		 renderJson(ret);
	 }
	 
	 /**
	  * 老师审核人脸
	  * 还要更新人脸
	  */
	 @ApiOper("老师审核人脸")
	 @UserType(conType = {1})
	 public void examineFace(
			 @NotEmpty @ApiPara(value = "faceLogId", notes = "人脸提交审核id") Integer faceLogId,
			 @NotEmpty @ApiPara(value = "state", notes = "状态") Integer state,
			 @ApiPara(value = "reason", notes = "理由（不通过必填）")String reason) throws Exception{
		 Ret ret = service.examineFace(faceLogId, state, reason);
		 renderJson(ret);
	 }
	 
	 /**
	  * 查看审核详情
	  */
	 @ApiOper("查看审核详情")
	 @UserType(conType = {1,2})
	 public void examineInfo(@NotEmpty @ApiPara(value = "faceLogId", notes = "人脸提交审核id") Integer faceLogId) throws Exception{
		 Integer accountId = getAttr("accountId");
		 Integer userType = getAttr("userType");
		 Ret ret = service.examineInfo(accountId, userType, faceLogId);
		 renderJson(ret);
	 }
	 
	 /**
	  * 学生获取自己审核列表
	  */
	 @ApiOper("学生获取自己审核列表")
	 @UserType(conType = {2})
	 public void examineList(
			 @NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page, 
			 @NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
		 Integer accountId = getAttr("accountId");
		 Integer userType = getAttr("userType");
		 Ret ret = service.examineList(accountId, userType, page, limit);
		 renderJson(ret);
	 }
	 
	 
	 
	 
	 
	 
	 
	 
	 
}
